package com.cyl.wms.controller;

import com.ruoyi.common.annotation.Log;
import com.cyl.wms.pojo.query.MaterialItemTypeQuery;
import com.cyl.wms.service.MaterialItemTypeService;
import com.cyl.wms.domain.MaterialItemType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description ="物料类型接口列表")
@RestController
@RequestMapping("/wms/materialType")
public class MaterialItemTypeController extends BaseController {
    @Autowired
    private MaterialItemTypeService service;
    @ApiOperation("查询全部物料类型列表")
    @PostMapping("/listAll")
    public ResponseEntity<List<MaterialItemType>> listAll(@RequestBody MaterialItemTypeQuery query) {
        List<MaterialItemType> list = service.selectListAll(query);
        return ResponseEntity.ok(list);
    }

    @ApiOperation("新增物料类型")
    @Log(title = "物料类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public ResponseEntity<String> add(@RequestBody MaterialItemType material) {
        if(service.insert(material) == 1){
            return ResponseEntity.ok("新增成功");
        }else {
            return ResponseEntity.ok("新增失败");
        }

    }
//
//
    @ApiOperation("删除物料类型")
    @Log(title = "物料类型", businessType = BusinessType.DELETE)
    @PostMapping("/delect")
    public ResponseEntity<String> remove(@RequestBody String ids) {
        if(service.deleteByIds(ids) == 1){
            return ResponseEntity.ok("删除成功");
        }else {
            return ResponseEntity.ok("删除失败，请先删除父节点");
        }
    }


}
